<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="租户号" prop="tenantId">
        <el-input
          v-model="queryParams.tenantId"
          placeholder="请输入租户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updatedBy">
        <el-input
          v-model="queryParams.updatedBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedTime">
        <el-date-picker clearable
          v-model="queryParams.updatedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="推荐人姓名" prop="ytjr">
        <el-input
          v-model="queryParams.ytjr"
          placeholder="请输入推荐人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请职务" prop="ysqzw">
        <el-select v-model="queryParams.ysqzw" placeholder="请选择申请职务" clearable>
          <el-option
            v-for="dict in dict.type.xyh_zw"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单位名称" prop="ydwmc">
        <el-input
          v-model="queryParams.ydwmc"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位性质" prop="ydwxz">
        <el-input
          v-model="queryParams.ydwxz"
          placeholder="请输入单位性质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位地址" prop="ydwdz">
        <el-input
          v-model="queryParams.ydwdz"
          placeholder="请输入单位地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主营业务" prop="yzyyw">
        <el-input
          v-model="queryParams.yzyyw"
          placeholder="请输入主营业务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位简介" prop="ydwjj">
        <el-input
          v-model="queryParams.ydwjj"
          placeholder="请输入单位简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照" prop="yyyzz">
        <el-input
          v-model="queryParams.yyyzz"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="yname">
        <el-input
          v-model="queryParams.yname"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="yphone">
        <el-input
          v-model="queryParams.yphone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位职务" prop="ydwzw">
        <el-input
          v-model="queryParams.ydwzw"
          placeholder="请输入单位职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="ysex">
        <el-select v-model="queryParams.ysex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="date" prop="ybirthday">
        <el-date-picker clearable
          v-model="queryParams.ybirthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择date">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="民族" prop="ymz">
        <el-input
          v-model="queryParams.ymz"
          placeholder="请输入民族"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯-省" prop="ysheng">
        <el-input
          v-model="queryParams.ysheng"
          placeholder="请输入籍贯-省"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯-市" prop="yshi">
        <el-input
          v-model="queryParams.yshi"
          placeholder="请输入籍贯-市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯-区" prop="yqu">
        <el-input
          v-model="queryParams.yqu"
          placeholder="请输入籍贯-区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="yxl">
        <el-input
          v-model="queryParams.yxl"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治面貌" prop="yzzmm">
        <el-select v-model="queryParams.yzzmm" placeholder="请选择政治面貌" clearable>
          <el-option
            v-for="dict in dict.type.xyh_yzzmm"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号" prop="ycard">
        <el-input
          v-model="queryParams.ycard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请状态" prop="ysqsta">
        <el-select v-model="queryParams.ysqsta" placeholder="请选择申请状态" clearable>
          <el-option
            v-for="dict in dict.type.xyh_sqsta"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份状态" prop="ysfstat">
        <el-select v-model="queryParams.ysfstat" placeholder="请选择身份状态" clearable>
          <el-option
            v-for="dict in dict.type.xyh_sfzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会员职务" prop="yhyzw">
        <el-select v-model="queryParams.yhyzw" placeholder="请选择会员职务" clearable>
          <el-option
            v-for="dict in dict.type.xyh_zw"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['xyh:member:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['xyh:member:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['xyh:member:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['xyh:member:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="租户号" align="center" prop="tenantId" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" />
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推荐人姓名" align="center" prop="ytjr" />
      <el-table-column label="申请职务" align="center" prop="ysqzw">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xyh_zw" :value="scope.row.ysqzw"/>
        </template>
      </el-table-column>
      <el-table-column label="单位名称" align="center" prop="ydwmc" />
      <el-table-column label="单位logo" align="center" prop="ydwlog" />
      <el-table-column label="单位性质" align="center" prop="ydwxz" />
      <el-table-column label="单位地址" align="center" prop="ydwdz" />
      <el-table-column label="主营业务" align="center" prop="yzyyw" />
      <el-table-column label="单位简介" align="center" prop="ydwjj" />
      <el-table-column label="营业执照" align="center" prop="yyyzz" />
      <el-table-column label="姓名" align="center" prop="yname" />
      <el-table-column label="手机号" align="center" prop="yphone" />
      <el-table-column label="单位职务" align="center" prop="ydwzw" />
      <el-table-column label="性别" align="center" prop="ysex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.ysex"/>
        </template>
      </el-table-column>
      <el-table-column label="date" align="center" prop="ybirthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ybirthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="ymz" />
      <el-table-column label="籍贯-省" align="center" prop="ysheng" />
      <el-table-column label="籍贯-市" align="center" prop="yshi" />
      <el-table-column label="籍贯-区" align="center" prop="yqu" />
      <el-table-column label="学历" align="center" prop="yxl" />
      <el-table-column label="政治面貌" align="center" prop="yzzmm">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xyh_yzzmm" :value="scope.row.yzzmm"/>
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="ycard" />
      <el-table-column label="申请状态" align="center" prop="ysqsta">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xyh_sqsta" :value="scope.row.ysqsta"/>
        </template>
      </el-table-column>
      <el-table-column label="身份状态" align="center" prop="ysfstat">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xyh_sfzt" :value="scope.row.ysfstat"/>
        </template>
      </el-table-column>
      <el-table-column label="会员职务" align="center" prop="yhyzw">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xyh_zw" :value="scope.row.yhyzw"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['xyh:member:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xyh:member:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="租户号" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户号" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="推荐人姓名" prop="ytjr">
          <el-input v-model="form.ytjr" placeholder="请输入推荐人姓名" />
        </el-form-item>
        <el-form-item label="申请职务" prop="ysqzw">
          <el-select v-model="form.ysqzw" placeholder="请选择申请职务">
            <el-option
              v-for="dict in dict.type.xyh_zw"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单位名称" prop="ydwmc">
          <el-input v-model="form.ydwmc" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="单位性质" prop="ydwxz">
          <el-input v-model="form.ydwxz" placeholder="请输入单位性质" />
        </el-form-item>
        <el-form-item label="单位地址" prop="ydwdz">
          <el-input v-model="form.ydwdz" placeholder="请输入单位地址" />
        </el-form-item>
        <el-form-item label="主营业务" prop="yzyyw">
          <el-input v-model="form.yzyyw" placeholder="请输入主营业务" />
        </el-form-item>
        <el-form-item label="单位简介" prop="ydwjj">
          <el-input v-model="form.ydwjj" placeholder="请输入单位简介" />
        </el-form-item>
        <el-form-item label="营业执照" prop="yyyzz">
          <el-input v-model="form.yyyzz" placeholder="请输入营业执照" />
        </el-form-item>
        <el-form-item label="姓名" prop="yname">
          <el-input v-model="form.yname" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="yphone">
          <el-input v-model="form.yphone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="单位职务" prop="ydwzw">
          <el-input v-model="form.ydwzw" placeholder="请输入单位职务" />
        </el-form-item>
        <el-form-item label="性别" prop="ysex">
          <el-radio-group v-model="form.ysex">
            <el-radio
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="date" prop="ybirthday">
          <el-date-picker clearable
            v-model="form.ybirthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择date">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="民族" prop="ymz">
          <el-input v-model="form.ymz" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="籍贯-省" prop="ysheng">
          <el-input v-model="form.ysheng" placeholder="请输入籍贯-省" />
        </el-form-item>
        <el-form-item label="市" prop="yshi">
          <el-input v-model="form.yshi" placeholder="请输入籍贯-市" />
        </el-form-item>
        <el-form-item label="区" prop="yqu">
          <el-input v-model="form.yqu" placeholder="请输入籍贯-区" />
        </el-form-item>
        <el-form-item label="学历" prop="yxl">
          <el-input v-model="form.yxl" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="yzzmm">
          <el-select v-model="form.yzzmm" placeholder="请选择政治面貌">
            <el-option
              v-for="dict in dict.type.xyh_yzzmm"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号" prop="ycard">
          <el-input v-model="form.ycard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="申请状态" prop="ysqsta">
          <el-select v-model="form.ysqsta" placeholder="请选择申请状">
            <el-option
              v-for="dict in dict.type.xyh_sqsta"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份状态" prop="ysfstat">
          <el-select v-model="form.ysfstat" placeholder="请选择身份状态">
            <el-option
              v-for="dict in dict.type.xyh_sfzt"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="会员职务" prop="yhyzw">
          <el-select v-model="form.yhyzw" placeholder="请选择会员职务">
            <el-option
              v-for="dict in dict.type.xyh_zw"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMember, getMember, delMember, addMember, updateMember } from "@/api/xyh/member";

export default {
  name: "Member",
  dicts: ['xyh_sfzt', 'xyh_zw', 'xyh_sqsta', 'sys_user_sex', 'xyh_yzzmm'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员信息表格数据
      memberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tenantId: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        ytjr: null,
        ysqzw: null,
        ydwmc: null,
        ydwlog: null,
        ydwxz: null,
        ydwdz: null,
        yzyyw: null,
        ydwjj: null,
        yyyzz: null,
        yname: null,
        yphone: null,
        ydwzw: null,
        ysex: null,
        ybirthday: null,
        ymz: null,
        ysheng: null,
        yshi: null,
        yqu: null,
        yxl: null,
        yzzmm: null,
        ycard: null,
        ysqsta: null,
        ysfstat: null,
        yhyzw: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ysqzw: [
          { required: false, message: "申请职务", trigger: "change" }
        ],
        ysex: [
          { required: false, message: "性别", trigger: "change" }
        ],
        yzzmm: [
          { required: false, message: "政治面貌", trigger: "change" }
        ],
        ysqsta: [
          { required: false, message: "申请状态", trigger: "change" }
        ],
        ysfstat: [
          { required: false, message: "身份状态", trigger: "change" }
        ],
        yhyzw: [
          { required: false, message: "会员职务", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员信息列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tenantId: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        ytjr: null,
        ysqzw: null,
        ydwmc: null,
        ydwlog: null,
        ydwxz: null,
        ydwdz: null,
        yzyyw: null,
        ydwjj: null,
        yyyzz: null,
        yname: null,
        yphone: null,
        ydwzw: null,
        ysex: null,
        ybirthday: null,
        ymz: null,
        ysheng: null,
        yshi: null,
        yqu: null,
        yxl: null,
        yzzmm: null,
        ycard: null,
        ysqsta: null,
        ysfstat: null,
        yhyzw: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMember(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMember(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会员信息编号为"' + ids + '"的数据项？').then(function() {
        return delMember(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('xyh/member/export', {
        ...this.queryParams
      }, `member_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
